﻿using CheemsControl.Demo.Views;
using Prism.Commands;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;
using System.Windows;

namespace CheemsControl.Demo.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private string _title = "Prism Application";
        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }

        IRegionManager _regionManager;
        IContainerProvider _containerProvider;
        public MainWindowViewModel(IRegionManager regionManager, IContainerProvider containerProvider)
        {
            this._regionManager = regionManager;
            this._containerProvider = containerProvider;

        }



        private DelegateCommand<string> _openControlWindow;
        public DelegateCommand<string> OpenControlWindowCommand =>
            _openControlWindow ?? (_openControlWindow = new DelegateCommand<string>(ExecuteOpenControlWindowCommand));

        void ExecuteOpenControlWindowCommand(string parameter)
        {
            var window = _containerProvider.Resolve<object>(parameter) as Window;
            if (window != null)
            {
                window.Owner = _containerProvider.Resolve<MainWindow>();
                window.Show();
            }
        }
    }
}
